//
//  RCDataBaseManager.m
//  RCDataBaseProject
//
//  Created by Roiy on 2017/7/31.
//  Copyright © 2017年 Roiy. All rights reserved.
//

#import "RCDataBaseManager.h"

@interface RCDataBaseManager()

@end

@implementation RCDataBaseManager

#pragma mark ---Init Object--
+(instancetype)databaseWithPath:(NSString *)aPath
{
    return [[self alloc] initWithPath:aPath];
}

-(instancetype)initWithPath:(NSString *)path
{
    self = [super init];
    if (self) {
        _dataBase = nil;
        _dataBasePath = [path copy];
        _maxBusyRetryTimeInterval   = 2;
    }
    return self;
}

#pragma ---DataBase Transaction Method--
-(BOOL)beginTransaction
{
    BOOL transactionType = [self executeHandle:@"begin exclusive transaction"];
    if (transactionType) {
        _inTransaction = YES;
    }
    return transactionType;
}

-(BOOL)beginDeferredTransaction
{
    BOOL transactionType = [self executeHandle:@"begin deferred transaction"];
    if (transactionType) {
        _inTransaction = YES;
    }
    return transactionType;
}

-(BOOL)commitTransaction
{
    BOOL transactionType = [self executeHandle:@"commit transaction"];
    if (transactionType){
        _inTransaction = NO;
    }
    return transactionType;
}

-(BOOL)rollbackTransaction
{
    BOOL transactionType = [self executeHandle:@"rollback transaction"];
    if (transactionType) {
        _inTransaction = NO;
    }
    
    return transactionType;
}

#pragma ---DataBase Encryption Method --
-(BOOL)setDataBaseKey:(NSString *)dbKey
{
    return [self setKeyWithData:[NSData dataWithBytes:(void *)[dbKey UTF8String] length:(NSInteger)strlen([dbKey UTF8String])]];
}

-(BOOL)setKeyWithData:(NSData *)keyData
{
    if (!keyData) {
        return NO;
    }
    //hongkunpeng  使用了私有api
//    int resultHandle = sqlite3_key(_dataBase, [keyData bytes], (int)[keyData length]);
    return NO;
}

-(BOOL)reSetDataBaseKey:(NSString *)dbKey
{
    return [self reSetDataBaseWithData:[NSData dataWithBytes:(void *)[dbKey UTF8String] length:(NSInteger)strlen([dbKey UTF8String])]];
}

-(BOOL)reSetDataBaseWithData:(NSData *)keyData
{
    if (!keyData) {
        return NO;
    }
    //hongkunpeng  使用了私有api
//    int resultHandle = sqlite3_rekey(_dataBase, [keyData bytes], (int)[keyData length]);
    return NO;
}

#pragma mark ---DataBase ErrorMessage Method
-(int)lastDataBaseErrorCode
{
    return -1;
}

-(NSString *)lastDataBaseErrorMessage
{
    return nil;
}

#pragma ---DataBase Operation Protocal--
-(BOOL)openDB
{
    return nil;
}

-(BOOL)closeDB
{
    return nil;
}

-(BOOL)executeHandle:(NSString *)sql, ...
{
    return nil;
}

-(id)executeQuery:(NSString *)sql, ...
{
    return nil;
}

@end

@implementation RCStatement


@end
